//
//  SCHotelRoomInfoController.m
//  shangcheng
//
//  Created by Jie Jie on 2019/7/31.
//  Copyright © 2019 张艳江. All rights reserved.
//

#import "SCHotelRoomInfoController.h"
#import "SDCycleScrollView.h"
#import "SCHotelReserveViewController.h"

#define k_table_rl_space        13
#define k_bottom_view_h         50
#define k_table_view_cell_h     0
#define k_cycle_scrollView_h    kScreenW*281/375
#define k_header_room_view_h    kScreenW*154/375
#define k_header_remark_view_h  90
#define k_table_header_view_h   k_cycle_scrollView_h + k_header_room_view_h + k_header_remark_view_h

@interface SCHotelRoomInfoController ()<UITableViewDelegate , UITableViewDataSource,SDCycleScrollViewDelegate>

@property (nonatomic , strong) SDCycleScrollView  *cycle_scrollView;// 轮播图
@property (nonatomic , strong) UITableView *table_view;
@property (nonatomic , strong) UIView *bottom_view;

@property (nonatomic , strong) UILabel *price_label;
@property (nonatomic , strong) UIButton *reserve_button;

@end

@implementation SCHotelRoomInfoController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addSubview:self.table_view];
    [self.view addSubview:self.bottom_view];
  
}

-(UIView *)tabelHeaderViewInTopSection{
   
    UIView *header_view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, k_table_header_view_h)];
    [header_view addSubview:self.cycle_scrollView];
    
    UIButton *back_button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
    [back_button addTarget:self action:@selector(clickBackButton:) forControlEvents:UIControlEventTouchUpInside];
    [header_view addSubview:back_button];
    
    UIImageView *back_image = [[UIImageView alloc] initWithFrame:CGRectMake(7, 9, 10, 17)];
    back_image.image = [UIImage imageNamed:@"back"];
    [back_button addSubview:back_image];
    
    [header_view addSubview:[self createRoomView]];
    
    return header_view;
}

-(UIView *)createRoomView{
   
    UIView *room_view = [[UIView alloc] initWithFrame:CGRectMake(0, k_cycle_scrollView_h, kScreenW, k_header_room_view_h)];
    room_view.backgroundColor = [UIColor whiteColor];
    
    CGFloat label_h = k_header_room_view_h/5;
    CGFloat label_w = (kScreenW - k_table_rl_space*2)/2;
    CGFloat label_w_1 = kScreenW - k_table_rl_space*2;
    
    for (int i = 0; i < 3; i++) {
        UILabel *left_label = [[UILabel alloc] init];
        left_label.frame = CGRectMake(k_table_rl_space, label_h * i, label_w, label_h);
        left_label.text = @"早餐 无早餐";
        left_label.font = [UIFont systemFontOfSize:12.0f];
        left_label.textAlignment = NSTextAlignmentLeft;
        [room_view addSubview:left_label];
    }
    
    for (int j = 0; j < 3; j++) {
        UILabel *right_label = [[UILabel alloc] init];
        right_label.frame = CGRectMake(label_w + k_table_rl_space, label_h * j, label_w, label_h);
        right_label.text = @"面积 10m";
        right_label.font = [UIFont systemFontOfSize:12.0f];
        right_label.textAlignment = NSTextAlignmentLeft;
        [room_view addSubview:right_label];
    }
    
    for (int k = 0; k < 2; k++) {
        UILabel *left_label_1 = [[UILabel alloc] init];
        left_label_1.frame = CGRectMake(k_table_rl_space, (label_h*3)+ label_h * k, label_w_1, label_h);
        left_label_1.text = @"床型 单人床1.2*2.0米 2张";
        left_label_1.font = [UIFont systemFontOfSize:12.0f];
        left_label_1.textAlignment = NSTextAlignmentLeft;
        [room_view addSubview:left_label_1];
    }
    
    UIView *line_view = [[UIView alloc] initWithFrame:CGRectMake(k_table_rl_space, k_header_room_view_h + 1, label_w_1, 1)];
    line_view.backgroundColor = RGB(244, 244, 244);
    [room_view addSubview:line_view];
    
    UIView *remark_view = [[UIView alloc] initWithFrame:CGRectMake(0,  k_header_room_view_h + 1, kScreenW, k_header_remark_view_h)];
    remark_view.backgroundColor = [UIColor whiteColor];
    [room_view addSubview:remark_view];
    
    UILabel *remark_label = [[UILabel alloc] initWithFrame:CGRectMake(k_table_rl_space, 15, label_w_1, 20)];
    remark_label.text = @"不可取消";
    remark_label.textAlignment = NSTextAlignmentLeft;
    remark_label.font = [UIFont systemFontOfSize:13];
    [remark_view addSubview:remark_label];
    
    UILabel *remark_info_label = [[UILabel alloc] initWithFrame:CGRectMake(k_table_rl_space, remark_label.bottom +7, label_w_1, 40)];
    remark_info_label.text = @"xxxx前可免费取消，当前已过最晚可以取消时间，订单确认后不可以x取消/变更，如未入住，酒店将扣除全额房费";
    remark_info_label.textColor = RGB(163, 163, 163);
    remark_info_label.textAlignment = NSTextAlignmentLeft;
    remark_info_label.font = [UIFont systemFontOfSize:13];
    remark_info_label.numberOfLines = 2;
    [remark_view addSubview:remark_info_label];
    
    return room_view;
    
}

-(UITableView *)table_view{
    
    if (_table_view == nil) {
        _table_view = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH - k_bottom_view_h)];
        _table_view.delegate = self;
        _table_view.dataSource = self;
        _table_view.backgroundColor = RGB(244, 244, 244);
        _table_view.tableFooterView = [[UIView alloc] init];
        [_table_view setTableHeaderView:[self tabelHeaderViewInTopSection]];
        
    }
    return _table_view;
}

-(SDCycleScrollView *)cycle_scrollView{
    
    if (_cycle_scrollView == nil) {
        
        _cycle_scrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreenW, k_cycle_scrollView_h) delegate:self placeholderImage:[UIImage imageWithColor:BGColor]];
        _cycle_scrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        _cycle_scrollView.currentPageDotColor = RGB(251, 30, 72);
        _cycle_scrollView.pageDotColor = [UIColor whiteColor];
        _cycle_scrollView.autoScrollTimeInterval = 3.0f;
        _cycle_scrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    }
    return _cycle_scrollView;
    
}

-(UILabel *)price_label{
    
    if (_price_label == nil) {
        _price_label = [[UILabel alloc] initWithFrame:CGRectMake(k_table_rl_space, 0, (kScreenW - k_table_rl_space) * 0.65, k_bottom_view_h)];
        _price_label.text = @"¥199";
        _price_label.textColor = RGB(219, 52, 52);
        _price_label.textAlignment = NSTextAlignmentLeft;
        _price_label.font = [UIFont systemFontOfSize:18];
    }
    return _price_label;
}

-(UIButton *)reserve_button{
    
    if (_reserve_button == nil) {
        _reserve_button = [[UIButton alloc] initWithFrame:CGRectMake((kScreenW - k_table_rl_space) * 0.65 + k_table_rl_space, 0, (kScreenW - k_table_rl_space) * 0.35, k_bottom_view_h)];
        [_reserve_button setTitle:@"预定" forState:UIControlStateNormal];
        [_reserve_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_reserve_button setBackgroundColor:RGB(231, 157, 58)];
        _reserve_button.titleLabel.font = [UIFont systemFontOfSize:15];
        [_reserve_button addTarget:self action:@selector(clickReserveButton:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _reserve_button;
}

-(UIView *)bottom_view{
    if (_bottom_view == nil) {
        _bottom_view = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenH - k_bottom_view_h, kScreenW, k_bottom_view_h)];
        _bottom_view.backgroundColor = [UIColor whiteColor];
        
        [_bottom_view addSubview:self.price_label];
        [_bottom_view addSubview:self.reserve_button];
    }
    return _bottom_view;
}

-(void)clickBackButton:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)clickReserveButton:(UIButton *)sender{
    
    SCHotelReserveViewController *vc = [[SCHotelReserveViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 0;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identifity1 = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifity1];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifity1 ];
    }
    return cell;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return k_table_view_cell_h;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
   
    
}


@end
